<?php

namespace plugin\admin\app\model;

use Illuminate\Database\Eloquent\Casts\Attribute;
use plugin\admin\app\model\Base;

/**
 * @property integer $id (主键)
 * @property integer $user_id 用户id
 * @property string $price 金额
 * @property string $name 姓名
 * @property string $card 银行卡号
 * @property string $bank 开户行
 * @property integer $status 状态，0：审核中，1：已打款，2：已拒绝
 * @property string $created_at 
 * @property string $updated_at
 */
class Withdraw extends Base
{

    protected $appends = [
        'bank'
    ];

    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_withdraw';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';

    protected $guarded = [];

    public static function getSn()
    {
        return 'TX'.date('YmdHis') . str_pad(rand(10000, 99999), 5, '0', STR_PAD_LEFT);

    }

    protected function bank(): Attribute
    {
        return Attribute::make(get: function ($value, $attributes) {
            if (!empty($attributes['bank_id'])){
                return Bank::where('id',$attributes['bank_id'])->value('name');
            }
            return '';
        });
    }
    
    
    
}
